
import os
import random
from tqdm import tqdm
import shutil
import os.path
jpg_path = r'/home/xys/CloundShiProjects/traffic_light/trafficlight_classify/test-筛选/error/ng/'  #jpg和txt混合路径
xml_path = r'/home/xys/CloundShiProjects/larger_objet_Projects/mine_larger_obj/JPEGImages/'     #txt保存路径
save_jpg_path = r'/home/xys/CloundShiProjects/traffic_light/trafficlight_classify/data-testandyuan/test/'       #图片路径
save_xml_path = r'/home/xys/PycharmProjects/pythonProject/yolov5/larger/labels/train/'
save_jpg_path_val = r'/home/xys/PycharmProjects/pythonProject/yolov5/larger/images/val/'
save_xml_path_val = r'/home/xys/PycharmProjects/pythonProject/yolov5/larger/labels/val/'

error_path = '/home/xys/CloundShiProjects/traffic_light/trafficlight_dect/crop-classify/筛选完毕的类/huang-zuo/'
save_jpg_path_test = r'/home/xys/CloundShiProjects/traffic_light/trafficlight_dect/crop-classify/crop-all/test/huang-zuo/'
save_xml_path_test = r'/home/xys/CloundShiProjects/traffic_light/trafficlight_dect/data/Annotations/'

file_names = os.listdir(jpg_path)#从测试文件夹ng删除文件
for files in file_names:
    file_name = os.listdir(jpg_path+files)
    for file in file_name:
        os.remove(save_jpg_path+files+'/'+file)

# random.shuffle(file_names)
# lens = len(file_names)
# for file in tqdm(file_names[0:int(0.1*lens)]):
#     file_back = file[-4:]
#     file_front = file[:-4]
#     if file_back == ".jpg":
#         os.remove(jpg_path + file)
#         shutil.copy(os.path.join(jpg_path, file), save_xml_path)
#         shutil.copy(os.path.join(xml_path,file_front+'.jpg'),save_jpg_path)
# for file in tqdm(file_names[int(0.9*lens):lens]):
#     file_back = file[-4:]
#     file_front = file[:-4]
#     if file_back == ".txt":
#         # os.remove(mix_file_path + file)
#         shutil.copy(os.path.join(jpg_path, file), save_xml_path_val)
#         shutil.copy(os.path.join(xml_path,file_front+'.jpg'),save_jpg_path_val)






#
# file_names = os.listdir(error_path)
# num = 0
# for file in tqdm(file_names):                                                   # 分开txt和img
#     file_back = file[-4:]
#     file_front = file[:-4]
#     filename = file_front.split('_')[0]
#     if file_back in ['.jpg'] and os.path.exists(save_jpg_path_test+file_front + '.jpg'):
#         # and os.path.exists(jpg_path+filename+'.jpg') and os.path.exists(xml_path+filename+'.xml'):
#         # shutil.copy(os.path.join(jpg_path, filename + '.jpg'), save_jpg_path)
#         # shutil.copy(os.path.join(save_jpg_path_test, file_front + '.xml'), save_xml_path_test)
#         os.remove(save_jpg_path_test+file_front + '.jpg')
#         # os.remove(save_xml_path_test+file_front + '.xml')
#         # shutil.move(os.path.join(jpg_path, filename + '.jpg'), save_jpg_path)
#         # shutil.move(os.path.join(xml_path, filename + '.xml'), save_xml_path)
#         num+=1
# print(num)






#     if file_back in ['.jpg']:
#         x=os.path.join(jpg_path,file)
#         y=os.path.join(xml_path,file_front+'.xml')
#         os.remove(os.path.join(jpg_path,file))
#         os.remove(os.path.join(xml_path,file_front+'.xml'))
#         num+=1
#         shutil.copy(os.path.join(jpg_path, file), save_xml_path)
#         if os.path.exists(os.path.join(xml_path,file_front+'.jpg'):
#         shutil.copy(os.path.join(xml_path,file_front+'.xml'), save_jpg_path)
#         shutil.move(os.path.join(xml_path,file_front+'.jpg'), save_jpg_path)  # 将文件复制到设定的文件夹中
#         shutil.copy(os.path.join(jpg_path, file_front + '.jpg'), save_jpg_path)     #将文件移动到设定的文件夹中
#         os.remove(os.path.join(no_detector_path+file_front+'.xml'))
# print(num)